﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public class QuanDAO
    {
        private FDeal4Entities db;

        public QuanDAO()
        {
            db = new FDeal4Entities();
        }

        public List<QUAN> LietKe()
        {
            return db.QUAN.ToList();
        }

        public QUAN LayID(string id)
        {
            var tl = db.QUAN.SingleOrDefault(t => t.IDQUAN == id);
            return tl;
        }

        public QUAN TimTen(String keyWord)
        {
            var tl = db.QUAN.SingleOrDefault(t => t.TENQUAN.Contains(keyWord));
            return tl;
        }

        public bool Them(QUAN tl)
        {
            try
            {
                db.QUAN.AddObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Xoa(QUAN tl)
        {
            try
            {
                db.QUAN.DeleteObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Sua(QUAN tl)
        {
            try
            {
                QUAN t1 = db.QUAN.Single(t => t.IDQUAN == tl.IDQUAN);
                t1.IDQUAN = tl.IDQUAN;
                t1.TENQUAN = tl.TENQUAN;

            

                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
            	return false;
            }
        }
    }
}
